package com.auxgroup.smarthome.entity;


import org.hibernate.annotations.GenericGenerator;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;

/**
 * Created by fju on 2017/8/7.
 * 站内收件人表：信息 - 用户 关联
 */
@Entity
@Table(name = "sys_message_send")
public class SysMessageSendEntity {

    @Id
    @GeneratedValue(generator = "uuid2")
    @GenericGenerator(name = "uuid2", strategy = "uuid2")
    @Column(length = 36, nullable = false)
    private String messageSendId;

    @Column(nullable = false, length = 36)
    private String sysMessageId;

    @Column(nullable = false, length = 36)
    private String userId;

    //0.未阅 1.已阅 2.已删除
    @Column(nullable = false, length = 1)
    private Integer progress;

    private Long createdAt;

    /**
     * 发送人id
     */
    private String senderId;

    /**
     * 发送人姓名
     */
    private String senderName;

    public SysMessageSendEntity() {
    }

    public SysMessageSendEntity(String sysMessageId, String userId) {
        this.sysMessageId = sysMessageId;
        this.userId = userId;
        this.progress = 0;
    }

    public SysMessageSendEntity(String sysMessageId, String userId, String senderId, String senderName) {
        this.sysMessageId = sysMessageId;
        this.userId = userId;
        this.senderId = senderId;
        this.senderName = senderName;
        this.progress = 0;
    }

    public String getMessageSendId() {
        return messageSendId;
    }

    public void setMessageSendId(String messageSendId) {
        this.messageSendId = messageSendId;
    }

    public String getSysMessageId() {
        return sysMessageId;
    }

    public void setSysMessageId(String sysMessageId) {
        this.sysMessageId = sysMessageId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public Integer getProgress() {
        return progress;
    }

    public void setProgress(Integer progress) {
        this.progress = progress;
    }

    public Long getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Long createdAt) {
        this.createdAt = createdAt;
    }

    public String getSenderId() {
        return senderId;
    }

    public void setSenderId(String senderId) {
        this.senderId = senderId;
    }

    public String getSenderName() {
        return senderName;
    }

    public void setSenderName(String senderName) {
        this.senderName = senderName;
    }

    @PrePersist
    public void prePersist() {
        Instant instant = Instant.now(Clock.system(ZoneId.of("Asia/Shanghai")));
        this.createdAt = instant.getEpochSecond();
    }

}
